package com.springboot.activemq.customer.demo.code;

import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

@Slf4j
@EnableJms
@Component
public class ConsumeActivemqMessage {
    /**
     * containerFactory属性的值对应ActiveConfig类中的方法
     * queue模式用queue消息的处理方式
     * topic模式用topic消息的处理方式
     */

    /**
     * 监听消息生产者创建的消息名称：queue01
     * @param msg
     */
    @JmsListener(destination = "queue01",containerFactory = "queueListenerFactory")
    public void customer(String msg) {
        try {
            Thread.sleep(5000);//模拟 业务逻辑处理需要5s
            System.out.println("接收到的消息:"+msg);
        }catch (Exception e){

        }

    }

    /**
     * 监听延迟消息：delaySend01
     * @param msg
     */
    @JmsListener(destination = "delaySend01",containerFactory = "queueListenerFactory")
    public void customer2(String msg) {
        log.info("接收延时消息:" + msg);
    }

    /**
     * 订阅模式消息(topic)：监听
     * @param msg
     */
    @JmsListener(destination = "topic01",containerFactory = "topicListenerFactory")
    public void customer3(String msg) {
        log.info("收到订阅模式消息:" + msg);
    }
}
